#include <iostream>
#include <vector>

class Solution
{
public:
    // double pointer
    int RemoveDuplicates(std::vector<int> &nums)
    {
        if (nums.empty())
            return 0;
        int i = 0;
        int j = 0;
        for (; j < nums.size(); j++)
        {
            if (nums[j] != nums[i])
            {
                nums[++i] = nums[j];
            }
        }
        return i + 1;
    }

    // sliding window
    int GetSubMintLen(const std::vector<int> &nums, int s)
    {
        if (nums.empty())
            return 0;
        int i = 0;
        int j = 0;
        int sub_sum = nums[0];
        int min_sub_len = nums.size() + 1;
        while (j < nums.size())
        {
            sub_sum += nums[++j];
            while (sub_sum >= s)
            {
                min_sub_len = std::min(min_sub_len, j - i + 1);
                sub_sum -= nums[i++];
            }
        }
        return (min_sub_len > nums.size()) ? -1 : min_sub_len;
    }
};

int main()
{
    Solution sol;
    std::vector<int> nums{0, 1, 2, 4, 2, 3, 0};
    std::vector<int> sorted_nums{0, 0, 1, 1, 1, 2, 2, 3, 3, 4, 7, 7};
    std::cout << "RemoveDuplicates length: " << sol.RemoveDuplicates(sorted_nums) << std::endl;
    std::cout << "Min sub length: " << sol.GetSubMintLen(nums, 13) << std::endl;

    return 0;
}